package com.onesports.intelligent.k12.polarlight.controller.organization.config;

import cn.oneframework.common.utils.ResultUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.onesports.framework.kit.common.valid.Json;
import com.onesports.intelligent.k12.polarlight.constant.ApiPathConstants;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.UpdateStatesDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.organization.InsertOrganizationCampusDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.organization.PageOrganizationCampusDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.organization.UpdateOrganizationCampusDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.organization.PageOrganizationCampusVO;
import com.onesports.intelligent.k12.polarlight.service.campus.OrganizationCampusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * @author wangcx
 * @since 2022-7-12
 */
@Api(value = "机构端", tags = "机构端-校区管理")
@RestController
@RequestMapping(ApiPathConstants.ORGANIZATION_CAMPUS)
@RequiredArgsConstructor
@PreAuthorize("isAuthenticated()")
public class OrganizationCampusController {

    private final OrganizationCampusService service;


    @PostMapping("/add")
    @ApiOperation(value = "新增校区")
    public ResponseEntity add(@Valid @RequestBody InsertOrganizationCampusDTO dto)
    {
        service.add(dto);
        return ResultUtil.success("添加成功");
    }



    @PostMapping("/upd")
    @ApiOperation(value = "修改校区信息")
    public ResponseEntity upd(@Valid @RequestBody UpdateOrganizationCampusDTO dto)
    {
        service.upd(dto);
        return ResultUtil.success("修改成功");
    }


    @PostMapping("/updStatus")
    @ApiOperation(value = "启用禁用校区")
    public ResponseEntity updStatus(@Valid @RequestBody UpdateStatesDTO dto)
    {
        service.updStatus(dto);
        return ResultUtil.success("修改成功");
    }



    @PostMapping("/page")
    @ApiOperation(value = "分页查询校区列表", response = PageOrganizationCampusVO.class)
    public ResponseEntity<IPage<PageOrganizationCampusVO>> findPage(@Valid @RequestBody PageOrganizationCampusDTO dto) {
        return ResultUtil.success(this.service.selectOrganizationPage(new Page<>(dto.getPage(),dto.getRow()),dto));

    }


}